<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
</head>

<body>
    <div id="app">
        <h1>{{goodsDetail.title}}</h1>
        <h1>{{goodsDetail.price}}</h1>
        <img :src="goodsDetail.img" alt="">
    </div>
    <script src="https://cdn.bootcss.com/vue/2.6.4/vue.js"></script>
    <script src="https://cdn.bootcss.com/axios/0.19.0-beta.1/axios.js"></script>
    <script>
        function getParams(key) {
            var querystr = location.search.substring(1)
            var arr1 = querystr.split("&")
            for (let i = 0; i < arr1.length; i++) {
                var arr2 = arr1[i].split('=')
                if (arr2[0] === key)
                    return arr2[1]
            }
        }

        Vue.config.productionTip = false
        Vue.config.devtools = false

        new Vue({
            el: "#app",
            data: {
                goodsid: 0,
                goodsDetail: {}
            },
            mounted() {
                this.goodsid = getParams("id")
                this.getDetail()
            },
            methods: {
                getDetail() {
                    axios.get("data/goods.json").then(res => {
                        var result = res.data.filter((item) => {
                            return item.id === parseInt(this.goodsid)
                        })

                        if (result[0]) {
                            this.goodsDetail = result[0]
                        }
                    })
                }
            },
        })
    </script>
</body>

</html>